﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[CountPays] 
(
	@PayId int
)
RETURNS int
AS
BEGIN
	
	DECLARE @C int
	SET @C = 0;
	
	SELECT @C = COUNT(*) FROM PAY_IN_ON_INV_OUT WHERE PAYMENT_IN_ID = @PayId
	
	IF @C = 0
	BEGIN
		SET @C = 1
	END

	RETURN @C
END